package com.lineage.server.timecontroller.pc;

import com.lineage.config.ConfigOther;
import com.lineage.server.Shutdown;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Trade;
import com.lineage.server.serverpackets.S_CloseList;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.thread.PcOtherThreadPool;
import com.lineage.server.world.World;
import java.util.Collection;
import java.util.Iterator;
import java.util.TimerTask;
import java.util.concurrent.ScheduledFuture;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class GfxTimer extends TimerTask {
  private static final Log _log = LogFactory.getLog(GfxTimer.class);
  
  private ScheduledFuture<?> _timer;
  
  public void start() {
    int timeMillis = 60000;
    this._timer = PcOtherThreadPool.get().scheduleAtFixedRate(this, 60000L, 60000L);
  }
  
  public void run() {
    try {
      Collection<L1PcInstance> all = World.get().getAllPlayers();
      if (all.isEmpty())
        return; 
      Iterator<L1PcInstance> iter = all.iterator();
      while (iter.hasNext()) {
        L1PcInstance tgpc = iter.next();
        if (ConfigOther.newcharpra && tgpc.getnewcharpra() && tgpc.getLevel() >= ConfigOther.newcharpralv) {
          tgpc.setnewcharpra(false);
          tgpc.sendPackets((ServerBasePacket)new S_ServerMessage("您的等级已达新手保护机制。"));
        } 
        if (Shutdown.isSHUTDOWN) {
          L1Trade trade = new L1Trade();
          trade.tradeCancel(tgpc);
          tgpc.sendPackets((ServerBasePacket)new S_CloseList(tgpc.getId()));
        } 
      } 
    } catch (Exception localException) {
      _log.error("装备特效处理时间轴异常重启", localException);
      PcOtherThreadPool.get().cancel(this._timer, false);
      Object localObject = new GfxTimer();
      ((GfxTimer)localObject).start();
    } 
  }
}
